import apiClient from './client';
import { SessionItems, ChatSessionMessageItem } from '../types/chat';


/**
 * 获取聊天会话列表
 * @returns 聊天会话列表
 */
export const getChatSessionListApi = async (
    page: number,
    pageSize: number
): Promise<{
  code: number;
  message: string;
  page: number,
  total: number,
  page_size: number,
  data:SessionItems[];
}> => {
  return apiClient.get('/api/chat/v1/sessions', {page, page_size: pageSize });
};


/**
 * 获取聊天会话消息列表
 * @returns 聊天会话消息列表
 */
export const getChatSessionMessageApi = async (
    session_id: number,
    coach_id: number,
    lastMessageId: number
): Promise<{
  code: number;
  message: string;
  data: {
    start: number,
    end: number,
    has_more: boolean,
    result: ChatSessionMessageItem[]
  };
}> => {
  return apiClient.get('/api/chat/v1/message',
      { session_id,
        coach_id,
        last_id: lastMessageId 
      });
};


/**
 * 获取聊天会话消息列表
 * @returns 聊天会话消息列表
 */
export const getLastestMessageApi = async (
    session_id: number,
    last_id: number,
): Promise<{
  code: number;
  message: string;
  data: {
    start: number,
    end: number,
    result: ChatSessionMessageItem[]
  };
}> => {
  return apiClient.get('/api/chat/v1/lastest', { session_id, last_id  });
};


/**
 * 获取聊天会话消息列表
 * @returns 聊天会话消息列表
 */
export const addChatSessionMessageApi = async (
    session: ChatSessionMessageItem
): Promise<{
  code: number;
  message: string;
  data:ChatSessionMessageItem;
}> => {
  return apiClient.post('/api/chat/v1/message', { ...session });
};


/**
 * 更新聊天会话状态
 * @returns 聊天会话消息列表
 */
export const setChatSessionStatusApi = async (
    session_id: number,
): Promise<{
  code: number;
  message: string;
  data:SessionItems[];
}> => {
  return apiClient.put('/api/chat/v1/sessions', {session_id});
};


/**
 * 删除聊天会话
 * @returns 聊天会话消息列表
 */
export const deleteChatSessionApi = async (
    session_id: number
): Promise<{
  code: number;
  message: string;
  data:SessionItems[];
}> => {
  return apiClient.delete('/api/chat/v1/sessions', {session_id} );
};
